<?php

class controllerBase {
	protected $params;
	protected $module;
	protected $vars;
	protected $models = array();
	protected $helpers = array();
	protected $classes = array();
	protected $loader;
	protected $mode = AETHER_WEB;
	protected $view = true;
	protected $template = 'default';

	//Constructor
	function __construct($aether) {
		$this->aether = $aether; //Reference to the aether class
		$this->module = $this->aether->getModule();
		$this->h = $aether->helpers; //Reference to helpers
		$this->m = $aether->models; //Reference to models
		$this->loader = $aether->loader;
		$this->errorHandler = $aether->errorHandler;
		$this->loader->loadArray($this->helpers, $this->module, 'helper');
		$this->loader->loadArray($this->models, $this->module, 'model');
		$this->loader->loadArray($this->classes, $this->module, 'class');
		$this->params = $aether->getRouteVars(); //
		if(isset($_GET['ajax'])||isset($_POST['ajax'])) { //Set the ajax param
			$this->params['ajax'] = true;
		} else {
			$this->params['ajax'] = false;
		}
		if($aether->getMode()==AETHER_WEB) {
			$default = 'webDefault';
		} else {
			$default = 'cliDefault';
		}
		if($this->params['ajax']) {
			$default = 'ajaxDefault';
		}
		if($this->template=='default') {
			$this->template = $default;
		}
		$this->params['url'] = $this->aether->getUrl();
		if($this->params['url']=='/') {
			$this->params['url'] = '';
		}
	}
	
	function init() {}
	
	public function getParam($name) {
		if(isset($this->params[$name])) {
			return $this->params[$name];
		} else {
			return null;
		}
	}

	public function setParam($name, $value) {
		$this->params[$name] = $value;
	}

	public function setVar($name, $value) {
		$this->vars[$name] = $value;
	}

	public function getVar($name) {
		return $this->vars[$name];
	}

	public function getMode() {
		return $this->mode;
	}

	public function hasView() {
		return $this->view;
	}

	public function getTemplate() {
		return $this->template;
	}

	public function load($resource) {
		return $this->loader->load($resource, $this->module);
	}
}

?>
